home *** CD-ROM | disk | FTP | other *** search
- Path: sun001.spd.dsccc.com!spd!jmccarty
- From: jmccarty@spd.dsccc.com (Mike McCarty)
- Newsgroups: comp.lang.c
- Subject: Re: Easiest way to center a string?
- Date: 14 Feb 1996 19:54:33 GMT
- Organization: DSC Communications Corporation, Plano, Texas USA
- Message-ID: <4ftelp$b7l@sun001.spd.dsccc.com>
- References: <4fobka$1st@parlor.hiwaay.net> <3120d412.7714326@news.iquest.net>
- NNTP-Posting-Host: aplo139.spd.dsccc.com
-
- In article <3120d412.7714326@news.iquest.net>,
- Robert B. Clark <rclark@iquest.net> wrote:
- )On 12 Feb 1996 21:31:54 GMT, foxworth@hiwaay.net wrote:
- )
- )> I'm learning C, and one of my assignments requires that the output strings be
- )>centered on the screen. Is there a simple way of doing this that I have overlooked?
- )
- )Compute the left column by subtracting half of the string length from
- )half of the screen width; e.g.,
- )
- ) x=MAXCOL / 2 - strlen(str) / 2;
- )
- )where MAXCOL is the maximum number of columns available to you (text
- )mode DOS, 80 columns). 'x' will be the column in which you should start
- )printing your string.
- )
- )You didn't mention which platform you're compiling for, so I leave the
- )details of cursor positioning to you. If you're on a DOS machine, look
- )up gotoxy().
- )--
- )Robert B. Clark <rclark@iquest.net>
- )"Be wary of strong spirits. It can make you shoot at tax collectors...
- )and miss." --RAH
-
-
- Please do =not= use this code as it stands. It may do terrible things to
- your screen if the string does not fit into the field. Always check for
- fits before using such techniques.
-
- Mike
- ----
- char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
-
- I don't speak for DSC. <- They make me say that.
-